<!-- 报价 -->
<template>
	<ListLayout>

		<Tips :leftText="'派单时间:'+SendRepairInfo.createTime" :rightText="routerParams.text" :color="routerParams.color[routerParams.state]"> </Tips>

		<!-- 报价未通过-审核信息 -->
		<template v-if="Object.keys(ReviewInfo).length">
			<ReviewDetailCard :reviewInfo="ReviewInfo"></ReviewDetailCard>
		</template>
		<!-- 待报价、报价未通过-报价信息 -->
		<QuoteDetailCard :showQuoteInfo="ShowQuoteInfo" :quoteInfo="FactoryQuoteInfo"></QuoteDetailCard>
		<!-- 待报价、报价未通过-科室信息 -->
		<DepartmentDetailCard :sendRepairInfo="SendRepairInfo"></DepartmentDetailCard>
		<!-- 待报价、报价未通过-设备信息 -->
		<DeviceCard :sendRepairInfo="SendRepairInfo"></DeviceCard>
		<!-- 待报价、报价未通过-故障信息 -->
		<FaultCard :sendRepairInfo="SendRepairInfo"></FaultCard>



		<template #footer>
			<HButtonGroup @leftClick="onGiveUpQuote" @rightClick="onQuote">
				<template #left>
					放弃报价
				</template>
				<template #right>
					{{StateButtonText[routerParams.state].detailPageButtonText}}
				</template>
			</HButtonGroup>
		</template>
	</ListLayout>

</template>


<script>
	import ListLayout from '@/components/layout/listLayout.vue'
	import QuoteDetailCard from '@/components/card/sendRepair/factory/info/quoteDetail.vue'
	import DepartmentDetailCard from '@/components/card/sendRepair/department/info/departmentDetail.vue'
	import DeviceCard from '@/components/card/sendRepair/factory/info/device.vue'
	import FaultCard from '@/components/card/sendRepair/factory/info/fault.vue'
	import ReviewDetailCard from '@/components/card/sendRepair/factory/info/reviewDetail.vue'
	import Tips from '@/components/tips/orderTips.vue'
	import HButtonGroup from '@/components/buttonGroup/groupTwo.vue'
	import ReapirApi from '@/apis/repair.js'
	import { factoryState } from '@/sendRepair/factory/state.js'
	import SendRepairRouterConfig from '@/sendRepair/routerConfig.js'
	export default {

		components: {
			Tips,
			ListLayout,
			QuoteDetailCard,
			DepartmentDetailCard,
			DeviceCard,
			FaultCard,
			ReviewDetailCard,
			HButtonGroup,
		},

		data() {

			return {
				data: {},
				routerParams: {
					color: factoryState.colors,
					id: ''
				},

			}
		},

		computed: {
			StateButtonText() {
				return factoryState.buttonParams

			},
			//报价信息内容展示
			ShowQuoteInfo() {
				return !!Object.keys(this.FactoryQuoteInfo).length
			},
			// 厂家报价信息
			FactoryQuoteInfo() {
				let { manufacturerInfoVo, repairInfo } = this.data


				if (manufacturerInfoVo) {
					this.$set(manufacturerInfoVo, 'quoteEndTime', repairInfo?.quoteEndTime || '')
				}

				return manufacturerInfoVo || {}
			},
			// 	送修信息
			SendRepairInfo() {
				let { repairInfo } = this.data
				return repairInfo || {}
			},
			// 审核信息
			ReviewInfo() {
				let { repairQuoteConfirmVo } = this.data
				return repairQuoteConfirmVo || {}

			},

		},

		methods: {
			//报价
			onQuote() {
				console.log('onQuote');
				const {
					id
				} = this.routerParams
				wx.navigateTo({
					url: `${SendRepairRouterConfig.Factory.SubmitQuote}?id=${id}`
				})
			},
			//放弃报价
			onGiveUpQuote() {
				let self = this
				wx.showModal({
					title: '放弃报价',
					content: '确定放弃此次报价吗？放弃后将无法再次加入报价',
					cancelColor: '#98A5B3',
					confirmColor: '#409EFF',
					success(res) {
						if (res.confirm) {
							ReapirApi.factory.cancelQuote({
								repairId: self.routerParams.id
							}).then((res) => {
								wx.showToast({
									title: '提交成功',
									icon: 'success',
									complete() {
										wx.redirectTo({
											url: SendRepairRouterConfig.Factory.Index
										})
									}
								})
							});
						}
					}
				})



			}
		},
		async onLoad(query) {
			const {
				state,
				currStateToName,
				id
			} = query
			this.$set(this.routerParams, 'text', currStateToName)
			this.$set(this.routerParams, 'state', Number(state))
			this.$set(this.routerParams, 'id', id)
			let res = await ReapirApi.common.getDetail(id)
			if (res.code === 0) {
				this.data = res.body || {}
			}
		}
	}
</script>
<style lang="scss" scoped>

</style>
